# @Time:        2024/7/6 上午10:53
# @USER:        lihuizhuo
# @Site:        www.swust.edu.cn
# @File:        M
# @Software:    PyCharm
# @license:     Copyright(C), swust
# @Author:      huizhuo
# @Email:       huizhuoli@foxmail.com
# @Version:     V1.1.0
import os
import sys
import pygame

parent_dir = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__)))
print(parent_dir)
sys.path.insert(0, parent_dir)

# sys.path.insert(0, "/Users/lihuizhuo/PycharmProjects/2024-edu-prj/demo2")


from actor.soldier import ShootSoldier, WalkSoldier


def game_run():
    """
    游戏运行
    :return:
    """
    # pygame setup
    pygame.init()
    # set up the display 窗口
    screen = pygame.display.set_mode((1280, 720))
    clock = pygame.time.Clock()
    running = True
    backgroud = pygame.image.load("resources/images/welcome/welcome.jpg")

    work_soldier = WalkSoldier("resources/images/boy1.png",
                               50, 300,
                               "小明", 100)

    shoot_soldier = ShootSoldier("resources/images/chinese/red_army/red_army1.png",
                                 "resources/images/chinese/red_army/red_army1-1.png",
                                 100, 100, "战士", 100)

    while running:
        # poll for events
        # pygame.QUIT event means the user clicked X to close your window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                work_soldier.run(event.key)
                shoot_soldier.run(event.key)

        # fill the screen with a color to wipe away anything from last frame
        # screen.fill("purple")
        #
        screen.blit(backgroud, (0, 0))
        work_soldier.draw(surface=screen)
        shoot_soldier.draw(surface=screen)

        # RENDER YOUR GAME HERE

        # flip() the display to put your work on screen
        pygame.display.flip()

        clock.tick(20)  # limits FPS to 60

    pygame.quit()


if __name__ == '__main__':
    # print(ShootDir.not_shoot)
    game_run()

